//index.js
//获取应用实例
const app = getApp()
const api = require('../../utils/api.js');
Page({
	data: {
		phone: "",
		checkCode: "",
		smsTrue: false,
		countdown: 60,
		smsName: "获取验证码",
	},
	//事件处理函数
	login: function() {
		wx.switchTab({
			url: '../business/list'
		})
	},
	sendCode: function() {
		if(this.data.phone == "") {
			wx.showModal({
				title: '提示',
				content: "请输入手机号",
				showCancel: false,
				success: function(res) {

				}
			})
			return false;
		} else {
			if(!(/^1[34578]\d{9}$/.test(this.data.phone))) {
				wx.showModal({
					title: '提示',
					content: "手机号格式有误",
					showCancel: false,
					success: function(res) {

					}
				})
				return false;
			}
		}
		let _this = this;
//		api.sendSms({
//			data: {
//				phone: this.data.phone,
//			},
//			success: function(res) {
//				if(res.data.code == 0) {
//
//				}
//			},
//		});
		let out = setInterval(function() {
			if(_this.data.countdown == 0) {
				clearInterval(out);
			}
			_this.setTime();
		}, 1000);
	},
	setTime: function(e) {
		let _this = this;

		if(_this.data.countdown == 0) {
			_this.setData({
				smsTrue: false,
				countdown: 60,
				smsName: "获取验证码"
			});
		} else {
			let time = _this.data.countdown;
			time--;
			_this.setData({
				smsTrue: true,
				smsName: time,
				countdown: time
			});
		}

	},
	onLoad: function() {

	},
	input_phone: function(e) {
		this.setData({
			phone: e.detail.value,
		})
	},
	input_checkCode: function(e) {
		this.setData({
			checkCode: e.detail.value,
		})
	},
})